package com.mornd.gulimall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mornd.gulimall.common.core.result.AjaxResult;
import com.mornd.gulimall.product.entity.CategoryBrandRelation;
import com.mornd.gulimall.product.service.ICategoryBrandRelationService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.mornd.gulimall.common.core.result.AjaxResult.success;

/**
 * <p>
 * 品牌分类关联 前端控制器
 * </p>
 *
 * @author mornd
 * @since 2023-07-23
 */
@RestController
@RequestMapping("/product/categoryBrandRelation")
public class CategoryBrandRelationController {
    @Resource
    private ICategoryBrandRelationService categoryBrandRelationService;

    @GetMapping("/category/list")
    public AjaxResult categoryList(CategoryBrandRelation relation) {
        IPage<CategoryBrandRelation> list = categoryBrandRelationService.cateGoryList(relation);
        return success(list);
    }

    @PutMapping
    public AjaxResult save(@RequestBody @Validated CategoryBrandRelation relation) {
        categoryBrandRelationService.batchSave(relation);
        return success();
    }

    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable Long id) {
        categoryBrandRelationService.removeById(id);
        return success();
    }

}
